<?php

class Deposit extends CI_Model {

    function index($costumer_id) {
        $this->db->where('costumer_id', $costumer_id);
        $this->db->order_by('id', 'DESC');
        $q = $this->db->get('deposit');
        return $q;
    }

    function show_deposit($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('deposit');
        return $q->result();
    }

    function create($data) {
        $this->db->insert('deposit', $data);
        redirect('deposits/index/success');
    }

    function costumer_deposit() {
        $q = $this->db->get('deposit');
        return $q;
    }

    function confirm($id, $status) {
        $data = array(
            'status' => $status,
        );
        $this->db->where('id', $id);
        $this->db->update('deposit', $data);
        redirect('deposit_admins/index');
    }

    function delete($id) {
        $this->db->where('id', $id);
        $this->db->delete('deposit');
        redirect('deposit_admins/index');
    }

    function name($costumer_id) {
        $this->db->where('id', $costumer_id);
        $q = $this->db->get('costumer');
        return $q;
    }

    public function record_count() {
        return $this->db->count_all("deposit");
    }

    function fetch_costumer($limit, $start) {
        $this->db->order_by('id', 'DESC');
        $this->db->limit($limit, $start);
        $this->db->where('credit', 0);
        $query = $this->db->get("deposit");
        return $query;
    }

    function fee($id_user) {
        $this->db->where(array('id_user' => $id_user, 'status' => 1));
        $this->db->order_by('id', 'DESC');
        $query = $this->db->get("booking");
        return $query->result();
    }

    function refund_create($data) {
        $this->db->insert('refund', $data);
        redirect('deposits/history_refund/berhasil');
    }

    function hrefund($id) {
        $this->db->where('id_user', $id);
        $q = $this->db->get('refund');
        return $q->result();
    }

    function showrefund($id, $id_user) {
        $this->db->where(array('id' => $id, 'id_user' => $id_user));
        $q = $this->db->get('refund');
        return $q->result();
    }

    function pay($id_costumer, $price, $tgl, $jam, $keterangan, $date_create) {
        $data = array(
            'costumer_id' => $id_costumer,
            'credit' => $price,
            'status' => 1,
            'tgl_transfer' => $tgl,
            'jam' => $jam,
            'keterangan' => $keterangan,
            'date' => $date_create,
        );
        $this->db->insert('deposit', $data);
        return true;
    }

    function administrasi($id_costumer, $price, $tgl, $keterangan, $date_create) {
        $data = array(
            'costumer_id' => $id_costumer,
            'credit' => $price,
            'tgl_transfer' => $tgl,
            'keterangan' => $keterangan,
            'date' => $date_create,
        );
        $this->db->insert('deposit', $data);
        return true;
    }

}

?>
